import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import importToCDN from 'vite-plugin-cdn-import'
import ElementPlus from 'unplugin-element-plus/vite'
const version = new Date().getTime()
export default defineConfig({
  base:'/shop-admin-v3/portal',
  mode:"production",
  build:{
    minify:false,
    rollupOptions: {
       output: {
          manualChunks(id) {
            if (id.includes('node_modules')) {
               return id.toString().split('node_modules/')[1].split('/')[0].toString();
            }
          },
          chunkFileNames: `static/js/[name]-${version}-[hash].js`,
          entryFileNames: `static/js/[name]-${version}-[hash].js`,
          assetFileNames: `static/[ext]/[name]-${version}-[hash].[ext]`
        }
    }
  },
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
        resolvers: [ElementPlusResolver()],
    }),
    Components({
        resolvers: [ElementPlusResolver()],
    }),
    importToCDN({
        modules: [
        //   {
        //     name:"vue",
		//     var:"Vue",
		//     path:"https://cdn.bootcdn.net/ajax/libs/vue/3.3.4/vue.global.prod.js"
        //   },
        //   {
        //     name: "element-plus", // 依赖名称, 
        //     var: "ElementPlus",  // 全局变量名
        //     path: "https://unpkg.com/element-plus@2.7.8/dist/index.full.js", // CDN 链接
        //     css: "https://unpkg.com/element-plus@2.7.8/dist/index.css", // 依赖有css就填，没有就去掉这个
        //   },
        //   {
        //     name: "vue-router", 
        //     var: "VueRouter", 
        //     path: "https://cdn.bootcdn.net/ajax/libs/vue-router/4.2.4/vue-router.global.prod.js",
        //   },
        //   {
        //     name: 'vue-demi',//安装vue-demi并导入 因为pinia中有用vue依赖中的vue-demi
        //     var: 'VueDemi',
        //     path: 'https://cdn.bootcdn.net/ajax/libs/vue-demi/0.14.6/index.iife.js'
        //   }
        ],
    }),
    ElementPlus({
        // options
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
